const express=require('express');
const wearService=require('../services/wearService');
const phoneService=require('../services/phoneService');

var router=express.Router();

router.use('/kids',async (req,res,next)=>{
    //找出所有kid wear
    var GET=req.query;
    var kind=GET.kind;
    if(kind==undefined||kind==null||kind=={}||kind==[]){
        kind='kids';
    };
    var data=await wearService.findByKind(kind);
    var img1=[];
    for(var i=0;i<5;i++){
        img1.push(data.wears[i]);
    }
    // res.send(data);
    res.send({success:true,wears:img1});
})

router.use('/mens',async (req,res,next)=>{
    //找出所有kid wear
    var GET=req.query;
    var kind=GET.kind;
    if(kind==undefined||kind==null||kind=={}||kind==[]){
        kind='mens';
    };
    var data=await wearService.findByKind(kind);
    var img1=[];
    for(var i=0;i<5;i++){
        img1.push(data.wears[i]);
    }
    // res.send(data);
    res.send({success:true,wears:img1});
})
router.use('/womens',async (req,res,next)=>{
    //找出所有kid wear
    var GET=req.query;
    var kind=GET.kind;
    if(kind==undefined||kind==null||kind=={}||kind==[]){
        kind='women';
    };
    var data=await wearService.findByKind(kind);
    var img1=[];
    for(var i=0;i<5;i++){
        img1.push(data.wears[i]);
    }
    // res.send(data);
    res.send({success:true,wears:img1});
})

router.use('/mobiles',async (req,res,next)=>{
    //找出所有kid wear
    var GET=req.query;
    var kind=GET.kind;
    if(kind==undefined||kind==null||kind=={}||kind==[]){
        kind='iphone';
    };
    var data=await phoneService.findByKind(kind);
    var img1=[];
    for(var i=0;i<5;i++){
        img1.push(data.phones[i]);
    }
    // res.send(data);
    res.send({success:true,phones:img1});
})

exports.router=router;